package exam.wzb.jsp.service.impl;


import exam.wzb.jsp.dao.BookDao;
import exam.wzb.jsp.model.Book;
import exam.wzb.jsp.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    private BookDao bookDao;

    @Autowired
    public BookServiceImpl(BookDao bookDao) {
        this.bookDao = bookDao;
    }

    @Override
    public List<Book> findBooksByName(String name) {
        if (name == null || name.trim().isEmpty()) {
            // 可以处理所有书籍的查询
        }
        return bookDao.findBooks(name + "%"); // 假设使用LIKE查询
    }

    @Override
    public void deleteBookById(Integer id) {
        bookDao.deleteBook(id);
    }

    @Override
    public List<Book> getBooksByPage(int offset, int limit) {
        return bookDao.findBooksByPage(offset, limit);
    }
}
